#!/usr/bin/perl
# edgrace.pl
# Run by edquota to edit the grace times for some filesystem

$fs = $ENV{'QUOTA_FILESYS'};
$bt = $ENV{'QUOTA_BTIME'};
$bu = $ENV{'QUOTA_BUNITS'};
$ft = $ENV{'QUOTA_FTIME'};
$fu = $ENV{'QUOTA_FUNITS'};
$f = $ARGV[0];

my (@quotadata, @newquotadata, $i, %dir2dev, @mountlist, $dv, @line, %tunits);

$tunits{"0"} = "seconds";
$tunits{"1"} = "minutes";
$tunits{"2"} = "hours";
$tunits{"3"} = "days";

open(FILE, $f);
@quotadata = <FILE>;
close(FILE);

#open(MOUNTLIST, "/bin/mount|");
#@mountlist = <MOUNTLIST>;
#close(MOUNTLIST);

@mountlist = `mount 2>/dev/null`;

$i = 0;
while($i < @mountlist)
{
	@line = split(/\s+/, $mountlist[$i]);
	$dir2dev{$line[2]} = $line[0];
	$i++;
}
$dv = $dir2dev{$fs};

$i = 0;
while($i < @quotadata)
{
	@line = split(/\s+/, $quotadata[$i]);
	#print @line[1];
	if($line[1] eq $dv)
	{
		$line[2] = $bt.$tunits{"$bu"};
		$quotadata[$i] = join(" ", @line);
		$quotadata[$i] = $quotadata[$i]."\n";
	}
	$i++;
}

open(FILE, "> $f");
print FILE @quotadata;
close(FILE);
